import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBC {
    public static void main(String[] args) throws Exception{
        //创建连接
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/test1");
        //加载hive驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        //创建statement
        Statement stat = conn.createStatement();
        //执行SQL
        ResultSet rs = stat.executeQuery("select * from score limit 10");
        while (rs.next()){
            int id=rs.getInt(1);
            int score_name = rs.getInt(2);
            int score = rs.getInt(3);
            System.out.println(id + "," + score_name + "," + score);
        }
        rs.close();
        stat.close();
        conn.close();
    }
}
